/**
 * 查询应用列表
 */
function queryAppList() {
    $.ajax({
        type: 'GET',
        url: "/service/authorize/app/all",
        headers: {
            Authorization: JwtTokenUtils.getBearerHeader()
        },
        success: function (data) {
            for (let i = 0; i < data.length; i++) {
                let app = data[i];

                let appDiv = $(".app-component .templates .app-panel").clone();
                appDiv.attr("app-id", app.id);
                appDiv.css("display", "block");
                appDiv.find(".add-new-root-menu .type-value-wrap input[type='radio']").attr("name", "add-root-menu-type" + app.id);
                appDiv.find(".panel-title").text(app.name);
                appDiv.find(".id-value").text(app.id);
                appDiv.find(".code-value").text(app.code);
                appDiv.find(".name-value").text(app.name);
                appDiv.find(".uri-value").text(app.uri);
                appDiv.find(".description-value").text(app.description);

                appDiv.find(".edit-button").click(function () {

                    let editAppPanel = $(".app-component .templates .edit-panel").clone();
                    editAppPanel.attr("app-id", app.id);
                    editAppPanel.find(".panel-title").text("Modify App");
                    editAppPanel.find(".code-value").val(app.code);
                    editAppPanel.find(".code-value").attr("disabled", "disabled");
                    editAppPanel.find(".code-label").removeClass("required");
                    editAppPanel.find(".name-value").val(app.name);
                    editAppPanel.find(".uri-value").val(app.uri);
                    editAppPanel.find(".description-value").val(app.description);

                    addValidatorForEditAppPanel(editAppPanel);

                    editAppPanel.find(".save-button").click(function () {
                        editAppPanel.bootstrapValidator('validate');
                        let invalidFields = editAppPanel.data('bootstrapValidator').getInvalidFields();
                        if (invalidFields.length == 0) {
                            updateApp(editAppPanel);
                        }
                    });

                    editAppPanel.find(".cancel-button").click(function () {
                        editAppPanel.remove();
                        appDiv.css("display", "block");
                    });

                    editAppPanel.insertBefore($(this).parents(".app-panel"));
                    appDiv.css("display", "none");
                });

                appDiv.find(".delete-button").click(function () {
                    PromptWindowUtils.showDeletePrompt("Are you sure to delete this config?", function () {
                        $.ajax({
                            type: "DELETE",
                            contentType: "application/json;charset=utf-8",
                            url: "/service/authorize/app/delete/" + app.id,
                            dataType: "json",
                            headers: {
                                Authorization: JwtTokenUtils.getBearerHeader()
                            },
                            success: function () {
                                $(".app-component .app-list").empty();
                                queryAppList();
                                PromptWindowUtils.hideDeletePrompt();
                            }
                        });
                    });
                });

                appDiv.find(".show-list-button").click(function () {
                    if (appDiv.find(".menu-list").hasClass("expansion")) {
                        appDiv.find(".menu-list").removeClass("expansion");
                        $(this).removeClass("open");
                        let children = $(appDiv.find(".menu-list").find("children")[0]);
                        children.removeClass("show");
                    } else if (appDiv.find(".menu-list").hasClass("queried")) {
                        appDiv.find(".menu-list").addClass("expansion");
                        $(this).addClass("open");
                    } else {
                        queryRootMenus(appDiv);
                    }
                });


                let addRootMenuPanel = appDiv.find(".add-root-menu-panel");
                addValidatorForEditMenuPanel(addRootMenuPanel, app.id);

                appDiv.find(".add-root-menu").click(function () {
                    addRootMenuPanel.addClass("show");
                });

                appDiv.find(".add-root-menu-panel .ok-button").click(function () {
                    let invalidFields = addRootMenuPanel.data('bootstrapValidator').getInvalidFields();
                    if (invalidFields.length == 0) {
                        addRootMenu(appDiv);
                    }
                });

                appDiv.find(".add-root-menu-panel .reset-button").click(function () {
                    appDiv.find(".add-root-menu-panel input:radio[value='0']").prop("checked", "true");
                    appDiv.find(".add-root-menu-panel input[type=text]").val("");
                    appDiv.find(".add-root-menu-panel textarea").val("");
                });

                appDiv.find(".add-root-menu-panel .close-button").click(function () {
                    appDiv.find(".add-root-menu-panel").removeClass("show");
                });

                $(".app-component .app-list").append(appDiv);
            }
        }
    });
}

/**
 *
 * 添加一个新的根菜单
 *
 * @param appDiv
 */
function addRootMenu(appDiv) {
    let appId = appDiv.attr("app-id");
    let addRootMenuPanel = appDiv.find(".add-root-menu-panel");
    let type = addRootMenuPanel.find("input:radio:checked").val();
    let code = addRootMenuPanel.find(".code-value").val();
    let name = addRootMenuPanel.find(".name-value").val();
    let description = addRootMenuPanel.find(".description-value-textarea").val();

    let requestData = {
        type: type,
        code: code,
        name: name,
        description: description,
        appId: appId
    };
    $.ajax({
        type: "POST",
        url: "/service/authorize/menu/addRootMenu",
        contentType: "application/json;charset=utf-8",
        headers: {
            Authorization: JwtTokenUtils.getBearerHeader()
        },
        data: JSON.stringify(requestData),
        success: function () {
            queryRootMenus(appDiv);
        }
    });
}

/**
 *
 * 为菜单icon增加事件处理
 *
 * @param menuPanel
 */
function handleMenuIconClick(menuPanel) {
    let menuIcon = menuPanel.children(".self").children(".menu-icon");
    let childrenDiv = menuPanel.children(".children");
    if (!menuIcon.hasClass("open") && !menuPanel.hasClass("queried")) {
        if (menuIcon.hasClass("menu")) {
            queryButtons(menuPanel)
        } else {
            queryMenus(menuPanel);
        }
    } else if (!menuIcon.hasClass("open")) {
        menuIcon.addClass("open");
        childrenDiv.addClass("show");
    } else if (menuIcon.hasClass("open")) {
        menuIcon.removeClass("open");
        childrenDiv.removeClass("show");
    }
}

/**
 *
 * 为菜单中的添加按钮增加事件处理
 *
 * @param menuPanel
 */
function handleAddButtonClick(menuPanel) {
    let appId = menuPanel.parents(".app-panel").attr("app-id");
    let menuId = menuPanel.attr("menu-id");
    if (menuPanel.attr("type") === "menu") {
        if (menuPanel.children(".edit-button-panel.add").length != 0) {
            return;
        }
        let addButtonDiv = $(".app-component .templates .edit-button-panel").clone();
        addButtonDiv.addClass("add");
        addButtonDiv.find(".subject").text("Add Button");
        addValidatorForEditButtonPanel(addButtonDiv, menuId);
        addButtonDiv.find(".cancel-button").click(function () {
            addButtonDiv.remove();
        });
        addButtonDiv.find(".save-button").click(function () {
            let invalidFields = addButtonDiv.data('bootstrapValidator').getInvalidFields();
            if (invalidFields.length > 0) {
                return;
            }
            let code = addButtonDiv.find(".code-value").val();
            let name = addButtonDiv.find(".name-value").val();
            let description = addButtonDiv.find(".description-value").val();
            let requestData = {
                code: code,
                name: name,
                description: description,
                menuId: menuId
            };
            $.ajax({
                type: "POST",
                contentType: "application/json;charset=utf-8",
                url: "/service/authorize/button/add",
                dataType: "json",
                headers: {
                    Authorization: JwtTokenUtils.getBearerHeader()
                },
                data: JSON.stringify(requestData),
                success: function () {
                    menuPanel.children(".children").children("ul").empty();
                    addButtonDiv.remove();
                    queryButtons(menuPanel);
                }
            });
        });
        addButtonDiv.insertBefore(menuPanel.children(".children"));
    } else if (menuPanel.attr("type") === "menu-folder") {
        if (menuPanel.children(".edit-menu-panel.add").length != 0) {
            return;
        }
        let addMenuDiv = $(".app-component .templates .edit-menu-panel").clone();
        addMenuDiv.addClass("add");
        addMenuDiv.find(".type-value-wrap input:radio").attr("name", "menu-type-value" + menuId);
        addMenuDiv.find(".subject").text("Add child menu");
        addValidatorForEditMenuPanel(addMenuDiv, appId);
        addMenuDiv.find(".cancel-button").click(function () {
            addMenuDiv.remove();
        });
        addMenuDiv.find(".save-button").click(function () {
            let invalidFields = addMenuDiv.data('bootstrapValidator').getInvalidFields();
            if (invalidFields.length > 0) {
                return;
            }
            let type = addMenuDiv.find("input:radio[name='" + "menu-type-value" + menuId + "']:checked").val();
            let code = addMenuDiv.find(".code-value").val();
            let name = addMenuDiv.find(".name-value").val();
            let description = addMenuDiv.find(".description-value").val();
            let requestData = {
                type: type,
                code: code,
                name: name,
                description: description,
                parentId: menuId,
                appId: appId
            };
            $.ajax({
                type: "POST",
                contentType: "application/json;charset=utf-8",
                url: "/service/authorize/menu/addChildMenu",
                dataType: "json",
                headers: {
                    Authorization: JwtTokenUtils.getBearerHeader()
                },
                data: JSON.stringify(requestData),
                success: function () {
                    menuPanel.children(".children").children("ul").empty();
                    addMenuDiv.remove();
                    queryMenus(menuPanel);
                }
            });
        });
        addMenuDiv.insertBefore(menuPanel.children(".children"));
    }
}

/**
 *
 * 菜单类型修改按钮点击事件处理
 *
 * @param panel
 * @param menu
 */
function handleMenuTypeModifyButtonClick(panel, menu) {
    if (panel.children(".edit-menu-panel.modify").length != 0) {
        return;
    }

    let menuId = menu.id;
    let modifyMenuDiv = $(".app-component .templates .edit-menu-panel").clone();
    modifyMenuDiv.addClass("modify");
    modifyMenuDiv.find(".subject").text("Modify Menu");
    modifyMenuDiv.find(".type-element").remove();
    modifyMenuDiv.find(".code-value").attr("disabled", "disabled");
    modifyMenuDiv.find(".code-value").val(menu.code);
    modifyMenuDiv.find(".name-value").val(menu.name);
    modifyMenuDiv.find(".description-value").val(menu.description);
    addValidatorForEditMenuPanel(modifyMenuDiv, menu.appId);
    modifyMenuDiv.find(".cancel-button").click(function () {
        modifyMenuDiv.remove();
    });
    modifyMenuDiv.find(".save-button").click(function () {
        let invalidFields = modifyMenuDiv.data('bootstrapValidator').getInvalidFields();
        if (invalidFields.length > 0) {
            return;
        }

        let name = modifyMenuDiv.find(".name-value").val();
        let uri = modifyMenuDiv.find(".uri-value").val();
        let description = modifyMenuDiv.find(".description-value").val();
        let requestData = {
            id: menuId,
            name: name,
            uri: uri,
            description: description
        };
        $.ajax({
            type: "PUT",
            contentType: "application/json;charset=utf-8",
            url: "/service/authorize/menu/update",
            dataType: "json",
            headers: {
                Authorization: JwtTokenUtils.getBearerHeader()
            },
            data: JSON.stringify(requestData),
            success: function () {
                let parentPanel = $(panel.parents(".menu-panel")[0]);
                parentPanel.children(".children").children("ul").empty();
                modifyMenuDiv.remove();
                queryMenus(parentPanel);
            }
        });
    });
    modifyMenuDiv.insertBefore(panel.children(".children"));
}

/**
 *
 * 按钮类型修改按钮点击事件处理
 *
 * @param panel
 * @param button
 */
function handleButtonTypeModifyButtonClick(panel, button) {
    if (panel.children(".edit-button-panel.modify").length != 0) {
        return;
    }

    let buttonId = button.id;
    let modifyButtonDiv = $(".app-component .templates .edit-button-panel").clone();
    modifyButtonDiv.addClass("modify");
    modifyButtonDiv.find(".subject").text("Modify Button");
    modifyButtonDiv.find(".code-value").attr("disabled", "disabled");
    modifyButtonDiv.find(".code-value").val(button.code);
    modifyButtonDiv.find(".name-value").val(button.name);
    modifyButtonDiv.find(".description-value").val(button.description);
    addValidatorForEditButtonPanel(modifyButtonDiv);
    modifyButtonDiv.find(".cancel-button").click(function () {
        modifyButtonDiv.remove();
    });
    modifyButtonDiv.find(".save-button").click(function () {
        let invalidFields = modifyButtonDiv.data('bootstrapValidator').getInvalidFields();
        if (invalidFields.length > 0) {
            return;
        }

        let name = modifyButtonDiv.find(".name-value").val();
        let description = modifyButtonDiv.find(".description-value").val();
        let requestData = {
            id: buttonId,
            name: name,
            description: description
        };
        $.ajax({
            type: "PUT",
            contentType: "application/json;charset=utf-8",
            url: "/service/authorize/button/update",
            dataType: "json",
            headers: {
                Authorization: JwtTokenUtils.getBearerHeader()
            },
            data: JSON.stringify(requestData),
            success: function () {
                let parentPanel = $(panel.parents(".menu-panel")[0]);
                parentPanel.children(".children").children("ul").empty();
                modifyButtonDiv.remove();
                queryButtons(parentPanel);
            }
        });
    });
    modifyButtonDiv.insertAfter(panel.children(".self"));
}

/**
 *
 * 删除按钮点击事件处理
 *
 * @param panel
 */
function handleDeleteButtonClick(panel) {
    if (panel.attr("type") === "menu" || panel.attr("type") === "menu-folder") {
        PromptWindowUtils.showDeletePrompt("Are you sure to delete this menu？", function () {
            let menuId = panel.attr("menu-id");
            $.ajax({
                type: "DELETE",
                contentType: "application/json;charset=utf-8",
                url: "/service/authorize/menu/delete/" + menuId,
                dataType: "json",
                headers: {
                    Authorization: JwtTokenUtils.getBearerHeader()
                },
                success: function () {
                    let parentPanel = $(panel.parents(".menu-panel")[0]);
                    parentPanel.children(".children").children("ul").empty();
                    queryMenus(parentPanel);
                    PromptWindowUtils.hideDeletePrompt();
                }
            });
        })
    } else if (panel.attr("type") === "button") {
        PromptWindowUtils.showDeletePrompt("Are you sure to delete this button？", function () {
            let buttonId = panel.attr("button-id");
            $.ajax({
                type: "DELETE",
                contentType: "application/json;charset=utf-8",
                url: "/service/authorize/button/delete/" + buttonId,
                dataType: "json",
                headers: {
                    Authorization: JwtTokenUtils.getBearerHeader()
                },
                success: function () {
                    let parentPanel = $(panel.parents(".menu-panel")[0]);
                    parentPanel.children(".children").children("ul").empty();
                    queryButtons(parentPanel);
                    PromptWindowUtils.hideDeletePrompt();
                }
            });
        })
    }
}

/**
 * 查询根菜单
 * @param appDiv app显示面板
 */
function queryRootMenus(appDiv) {
    let appId = appDiv.attr("app-id");
    $.ajax({
        type: "GET",
        url: "/service/authorize/menu/findRootMenuByApp/" + appId,
        headers: {
            Authorization: JwtTokenUtils.getBearerHeader()
        },
        success: function (data) {
            appDiv.find(".menu-list").empty();
            appDiv.find(".menu-list").addClass("expansion");
            if (!appDiv.find(".menu-list").hasClass("queried")) {
                appDiv.find(".menu-list").addClass("queried");
            }
            appDiv.find(".show-list-button").addClass("open");
            for (let i = 0; i < data.length; i++) {
                let menu = data[i];
                let menuPanel = $(".app-component .templates .menu-panel").clone();

                if (menu.type == 0) {
                    menuPanel.find(".menu-icon").addClass("menu");
                    menuPanel.attr("type", "menu");
                } else {
                    menuPanel.find(".menu-icon").addClass("menu-folder");
                    menuPanel.attr("type", "menu-folder");
                }
                menuPanel.attr("menu-id", menu.id);
                menuPanel.find(".menu-code").text(menu.code);
                menuPanel.find(".menu-name").text(menu.name);

                menuPanel.find(".menu-icon").click(function () {
                    handleMenuIconClick(menuPanel);
                });

                menuPanel.find(".add-button").click(function () {
                    handleAddButtonClick(menuPanel);
                });

                menuPanel.find(".modify-button").click(function () {
                    handleMenuTypeModifyButtonClick(menuPanel, menu);
                });

                menuPanel.find(".delete-button").click(function () {
                    handleDeleteButtonClick(menuPanel);
                });

                appDiv.find(".menu-list").append(menuPanel);
            }
        }
    });
}

/**
 * 查询子菜单
 * @param menuPanel 父级菜单
 */
function queryMenus(menuPanel) {
    let menuId = menuPanel.attr("menu-id");
    $.ajax({
        type: "GET",
        url: "/service/authorize/menu/findMenusByParent/" + menuId,
        headers: {
            Authorization: JwtTokenUtils.getBearerHeader()
        },
        success: function (data) {
            menuPanel.addClass("queried");
            let menuIcon = menuPanel.children(".self").children(".menu-icon");
            menuIcon.addClass("open");
            let childrenDiv = menuPanel.children(".children");
            childrenDiv.addClass("show");

            for (let i = 0; i < data.length; i++) {

                let li = $("<li></li>");

                let childMenu = data[i];
                let childMenuPanel = $(".app-component .templates .menu-panel").clone();

                if (childMenu.type == 0) {
                    childMenuPanel.find(".menu-icon").addClass("menu");
                    childMenuPanel.attr("type", "menu");
                } else {
                    childMenuPanel.find(".menu-icon").addClass("menu-folder");
                    childMenuPanel.attr("type", "menu-folder");
                }
                childMenuPanel.attr("menu-id", childMenu.id);
                childMenuPanel.find(".menu-code").text(childMenu.code);
                childMenuPanel.find(".menu-name").text(childMenu.name);

                childMenuPanel.find(".menu-icon").click(function () {
                    handleMenuIconClick(childMenuPanel);
                });

                childMenuPanel.find(".add-button").click(function () {
                    handleAddButtonClick(childMenuPanel);
                });

                childMenuPanel.find(".modify-button").click(function () {
                    handleMenuTypeModifyButtonClick(childMenuPanel, childMenu);
                });

                childMenuPanel.find(".delete-button").click(function () {
                    handleDeleteButtonClick(childMenuPanel);
                });

                li.append(childMenuPanel);
                childrenDiv.children("ul").append(li);
            }

        }
    });
}

/**
 * 查询按钮
 * @param menuPanel 父级菜单
 */
function queryButtons(menuPanel) {
    let menuId = menuPanel.attr("menu-id");
    $.ajax({
        type: "GET",
        url: "/service/authorize/button/findButtonsByMenu/" + menuId,
        headers: {
            Authorization: JwtTokenUtils.getBearerHeader()
        },
        success: function (data) {
            menuPanel.addClass("queried");
            let menuIcon = menuPanel.children(".self").children(".menu-icon");
            menuIcon.addClass("open");
            let childrenDiv = menuPanel.children(".children");
            childrenDiv.addClass("show");

            for (let i = 0; i < data.length; i++) {

                let li = $("<li></li>");

                let button = data[i];
                let buttonPanel = $(".app-component .templates .button-panel").clone();

                buttonPanel.attr("button-id", button.id);
                buttonPanel.attr("type", "button");
                buttonPanel.find(".button-code").text(button.code);
                buttonPanel.find(".button-name").text(button.name);

                buttonPanel.find(".modify-button").click(function () {
                    handleButtonTypeModifyButtonClick(buttonPanel, button);
                });

                buttonPanel.find(".delete-button").click(function () {
                    handleDeleteButtonClick(buttonPanel);
                });

                li.append(buttonPanel);
                childrenDiv.children("ul").append(li);
            }
        }
    });
}

/**
 * 给添加app的panel增加校验
 * @param editAppPanel
 */
function addValidatorForEditAppPanel(editAppPanel) {
    editAppPanel.bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            code: {
                group: '.input-div',
                validators: {
                    notEmpty: {
                        message: 'The code is required'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9\-\\.]+$/,
                        message: "Only characters, numbers, \"-\" or \".\" are allowed"
                    },
                    remote: {
                        type: 'GET',
                        headers: {
                            Authorization: JwtTokenUtils.getBearerHeader()
                        },
                        message: "No. already exists, please replace with a new one",
                        url: "/service/authorize/app/check/code",
                        delay: 1000
                    }
                }
            },
            name: {
                group: '.input-div',
                validators: {
                    notEmpty: {
                        message: 'The name is required'
                    }
                }
            }
        }
    });
}

/**
 * 给添加menu的panel增加校验
 * @param editMenuPanel
 * @param appId
 */
function addValidatorForEditMenuPanel(editMenuPanel, appId) {
    editMenuPanel.bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            code: {
                group: '.input-div',
                validators: {
                    notEmpty: {
                        message: 'The code is required'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9\-\\.]+$/,
                        message: "Only characters, numbers, \"-\" or \".\" are allowed"
                    },
                    remote: {
                        type: 'GET',
                        headers: {
                            Authorization: JwtTokenUtils.getBearerHeader()
                        },
                        data: {
                            appId: appId
                        },
                        message: "No. already exists, please replace with a new one",
                        url: "/service/authorize/menu/check/code",
                        delay: 1000
                    }
                }
            },
            name: {
                group: '.input-div',
                validators: {
                    notEmpty: {
                        message: 'The name is required'
                    }
                }
            }
        }
    });
}

/**
 * 给添加button的panel增加校验
 * @param editButtonPanel
 * @param appId app id
 */
function addValidatorForEditButtonPanel(editButtonPanel, menuId) {
    editButtonPanel.bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            code: {
                group: '.input-div',
                validators: {
                    notEmpty: {
                        message: 'The code is required'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9\-\\.]+$/,
                        message: "Only characters, numbers, \"-\" or \".\" are allowed"
                    },
                    remote: {
                        type: 'GET',
                        headers: {
                            Authorization: JwtTokenUtils.getBearerHeader()
                        },
                        data: {
                            menuId: menuId
                        },
                        message: "No. already exists, please replace with a new one",
                        url: "/service/authorize/button/check/code",
                        delay: 1000
                    }
                }
            },
            name: {
                group: '.input-div',
                validators: {
                    notEmpty: {
                        message: 'The name is required'
                    }
                }
            }
        }
    });
}

/**
 * 添加按钮点击事件处理
 * 添加新微服务div显示
 */
function addNewHandle() {
    if ($(".app-component .add-new-panel").hasClass("disable")) {
        return;
    }

    let addAppPanel = $(".app-component .templates .edit-panel").clone();
    addAppPanel.css("margin-bottom", "0");
    addAppPanel.find(".panel-title").text("Add App");
    addAppPanel.find(".save-button").click(function () {
        addAppPanel.bootstrapValidator('validate');
        let invalidFields = addAppPanel.data('bootstrapValidator').getInvalidFields();
        if (invalidFields.length == 0) {
            addApp(addAppPanel);
        }
    });

    addValidatorForEditAppPanel(addAppPanel);

    addAppPanel.find(".cancel-button").click(function () {
        addAppPanel.remove();
        $(".app-component .add-new-panel").removeClass("disable");
    });

    $(".app-component .add-app-div").append(addAppPanel);
    $(".app-component .add-new-panel").addClass("disable");
}

/**
 * 添加应用
 * @param addAppPanel
 */
function addApp(addAppPanel) {

    let requestData = {};
    requestData.code = addAppPanel.find(".code-value").val();
    requestData.name = addAppPanel.find(".name-value").val();
    requestData.uri = addAppPanel.find(".uri-value").val();
    requestData.description = addAppPanel.find(".description-value").val();

    $.ajax({
        type: 'POST',
        url: "/service/authorize/app/add",
        contentType: "application/json;charset=UTF-8",
        headers: {
            Authorization: JwtTokenUtils.getBearerHeader()
        },
        data: JSON.stringify(requestData),
        success: function () {
            addAppPanel.remove();
            $(".app-component .add-new-panel").removeClass("disable");
            $(".app-component .app-list").empty();
            queryAppList();
        }
    });
}

/**
 * 修改应用信息
 * @param editAppPanel
 */
function updateApp(editAppPanel) {
    let requestData = {};
    requestData.id = editAppPanel.attr("app-id");
    requestData.code = editAppPanel.find(".code-value").val();
    requestData.name = editAppPanel.find(".name-value").val();
    requestData.uri = editAppPanel.find(".uri-value").val();
    requestData.description = editAppPanel.find(".description-value").val();

    $.ajax({
        type: 'PUT',
        url: "/service/authorize/app/update",
        contentType: "application/json;charset=UTF-8",
        headers: {
            Authorization: JwtTokenUtils.getBearerHeader()
        },
        data: JSON.stringify(requestData),
        success: function () {
            $(".app-component .app-list").empty();
            queryAppList();
        }
    });
}

/**
 * 页面启动完成事件
 *
 * 1.查询微服务列表
 *
 *
 */
$(document).ready(function () {
    queryAppList();
});